#import "PotManager.h"

@implementation PotManager

#define COIN_STEP   5.0

- (NSImage *)imageWithNumberCoins:(int)numCoins
{
   NSRect r =  [potImage frame];
   NSImage *scratchImage = [[[NSImage allocWithZone:NULL] initWithSize:r.size]autorelease];
   NSImage *coin = [NSImage imageNamed:@"Coin"];
   unsigned i;

// lock focus on the destination image:
   [scratchImage lockFocus];

// set the color to transparent and fill it:
   [[NSColor clearColor] set];
   NSRectFill(NSMakeRect(0.0,0.0,r.size.width,r.size.height));

// step through and make that many coins:
   for (i = 0; i < numCoins; i++) {
        NSPoint origin = NSMakePoint(0.0,i*COIN_STEP);
        [coin compositeToPoint:origin operation:NSCompositeSourceOver];
   }

// NEVER forget to unlock focus!
   [scratchImage unlockFocus];
   return scratchImage;
}

- (void)updatePotAmount:(int)amount
{
    pot = amount;
    [potImage setImage:[self imageWithNumberCoins:rint(amount/100.0)]];
    [potField setStringValue:[NSString stringWithFormat:@"$ %d",amount]];
}

- (int)pot {
   return pot;
}

@end
